package com.pro.controller;

import com.pro.pojo.*;
import com.pro.service.JsExamineService;
import com.pro.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author YuQing
 * @date 2022/1/11 16:39
 */
@Controller
@RequestMapping(value = "examine")
public class JsExamineController {
    @Autowired
    private JsExamineService jsExamineService;

    @RequestMapping("/getExamineNum")
    @ResponseBody
    /**
     * @author: YuQing
     * @date: 2022/1/11
     * @description: 查询审核个数
     */
    public JsonData getExamineNum(Integer type) {
        JsCourseRecord record = new JsCourseRecord();
        record.setAllNum(jsExamineService.getExamineNum("", type));
        record.setApprovedNum(jsExamineService.getExamineNum("1", type));
        record.setAuditNum(jsExamineService.getExamineNum("2", type));
        record.setAuditFailedNum(jsExamineService.getExamineNum("3", type));
        List<JsCourseRecord> list = new ArrayList<>();
        list.add(record);
        return list!=null?JsonData.buildSuccess(list): JsonData.buildError("服务器出错了");
    }
    @RequestMapping("/updateRecordResult")
    @ResponseBody
    /**
     * @author: YuQing
     * @date: 2022/1/11
     * @description: 修改审核状态
     */
    public JsonData updateRecordResult(JsCourseRecord courseRecord){
        String date = DateUtils.tranferDateTimeToString(new Date());
        courseRecord.setImplementDate(date);
        Boolean update = jsExamineService.updateRecordResult(courseRecord);
        return update!=null?JsonData.buildSuccess(update): JsonData.buildError("服务器出错了");
    }
    @RequestMapping("/getCourseClass")
    @ResponseBody
    /**
     * @author: YuQing
     * @date: 2022/1/12
     * @description: 查询课程分类
     */
    public JsonData getCourseClass(){
        List<JsCourseClass> courseClass = jsExamineService.getCourseClass();
        return courseClass!=null?JsonData.buildSuccess(courseClass): JsonData.buildError("服务器出错了");
    }
    @RequestMapping("/getCourses")
    @ResponseBody
    /**
     * @author: YuQing
     * @date: 2022/1/12
     * @description: 查询课程
     */
    public JsonData getCourses(JsCourse course){
        List<JsCourse> courses = jsExamineService.getCourses(course);
        return courses!=null?JsonData.buildSuccess(courses): JsonData.buildError("服务器出错了");
    }
    @RequestMapping("/getCourseInformation")
    @ResponseBody
    /**
     * @author: YuQing
     * @date: 2022/1/12
     * @description: 查询课程详情
     */
    public JsonData getCourseInformation(Integer type,Integer id){
        JsCourse courseInformation = jsExamineService.getCourseInformation(type, id);
        return courseInformation!=null?JsonData.buildSuccess(courseInformation): JsonData.buildError("服务器出错了");
    }
    @RequestMapping("/searchCourse")
    @ResponseBody
    /**
     * @author: YuQing
     * @date: 2022/1/13
     * @description: 课程高级检索
     */
    public JsonData searchCourse(JsCourse course){
        List<JsCourse> courseList = jsExamineService.searchCourse(course);
        return courseList!=null?JsonData.buildSuccess(courseList): JsonData.buildError("服务器出错了");
    }
    @RequestMapping("/updateCourseRecord")
    @ResponseBody
    /**
     * @author: YuQing
     * @date: 2022/1/13
     * @description: 修改课程审核状态
     */
    public JsonData updateCourseRecord(JsCourse course){
        String date = DateUtils.tranferDateTimeToString(new Date());
        course.setUpdateDate(date);
        Boolean update = jsExamineService.updateCourseRecord(course);
        return update!=null?JsonData.buildSuccess(update): JsonData.buildError("服务器出错了");
    }
    @RequestMapping("/getActicleCategroy")
    @ResponseBody
    /**
     * @author: YuQing
     * @date: 2022/1/13
     * @description: 查询微圈分类
     */
    public JsonData getActicleCategroy(){
        List<JsActicleCategroy> acticleCategroy = jsExamineService.getActicleCategroy();
        return acticleCategroy!=null?JsonData.buildSuccess(acticleCategroy): JsonData.buildError("服务器出错了");
    }
    @RequestMapping("/getMicrocircle")
    @ResponseBody
    /**
     * @author: YuQing
     * @date: 2022/1/14
     * @description: 查询微圈
     */
    public JsonData getMicrocircle(JsMicrocircle microcircle){
        List<JsMicrocircle> microcircles = jsExamineService.getMicrocircle(microcircle);
        return microcircles!=null?JsonData.buildSuccess(microcircles): JsonData.buildError("服务器出错了");
    }
    @RequestMapping("/getMicrocircleInformation")
    @ResponseBody
    /**
     * @author: YuQing
     * @date: 2022/1/14
     * @description: 查询微圈详情
     */
    public JsonData getMicrocircleInformation(Integer type,Integer id){
        JsMicrocircle microcircleInformation = jsExamineService.getMicrocircleInformation(type, id);
        return microcircleInformation!=null?JsonData.buildSuccess(microcircleInformation): JsonData.buildError("服务器出错了");
    }
    @RequestMapping("/updateMicrocircleDetails")
    @ResponseBody
    /**
     * @author: YuQing
     * @date: 2022/1/14
     * @description: 修改微圈状态
     */
    public JsonData updateMicrocircleDetails(JsMicrocircle microcircle){
        String date = DateUtils.tranferDateTimeToString(new Date());
        microcircle.setUpdateDate(date);
        Boolean microcircleDetails = jsExamineService.updateMicrocircleDetails(microcircle);
        return microcircleDetails!=null?JsonData.buildSuccess(microcircleDetails): JsonData.buildError("服务器出错了");
    }
    @RequestMapping("/addAuditLog")
    @ResponseBody
    /**
     * @author: YuQing
     * @date: 2022/1/14
     * @description: 添加审核日志
     */
    public JsonData addAuditLog(JsAuditLog auditLog){
        String date = DateUtils.tranferDateTimeToString(new Date());
        auditLog.setCreateDate(date);
        Boolean addAudit = jsExamineService.addAuditLog(auditLog);
        return addAudit!=null?JsonData.buildSuccess(addAudit): JsonData.buildError("服务器出错了");
    }
    @RequestMapping("/getExamineLog")
    @ResponseBody
    /**
     * @author: YuQing
     * @date: 2022/1/14
     * @description: 查询审核日志
     */
    public JsonData getExamineLog(JsAuditLog auditLog){
        if(auditLog.getCreateDate() != null && auditLog.getCreateDate() != ""){
            auditLog.setCreateDate(auditLog.getCreateDate().substring(0,10));
        }
        List<JsAuditLog> examineLog = jsExamineService.getExamineLog(auditLog);
        return examineLog!=null?JsonData.buildSuccess(examineLog): JsonData.buildError("服务器出错了");
    }
    @RequestMapping("/deleteAuditLog")
    @ResponseBody
    /**
     * @author: YuQing
     * @date: 2022/1/14
     * @description: 删除审核日志
     */
    public JsonData deleteAuditLog(Integer id){
        Boolean deleteAudit = jsExamineService.deleteAuditLog(id);
        return deleteAudit!=null?JsonData.buildSuccess(deleteAudit): JsonData.buildError("服务器出错了");
    }

}
